package Jw20241017;

import java.util.*;

/**
 * Created with IntelliJ IDEA.
 * Description: 迷宫
 * User: 王圆豪
 * Date: 2024-10-19
 * Time: 14:19
 */
class Node{
    int i;
    int j;
    int dir;

    public Node(int i, int j){
        this.i = i;
        this.j = j;
    }

    public String toString(){
        return "(" + this.i + "," + this.j + ")";
    }
}

public class Test1{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[][] arr = new int[n][n];
        int[][] check = new int[n][n];
        for(int i = 0; i < n; i++){
            for(int j = 0; j < n; j++){
                arr[i][j] = sc.nextInt();
            }
        }
        int x = 0,y = 0;
        Stack<Node> stack = new Stack<>();
        stack.push(new Node(1, 1));
        check[1][1] = 1;
        while(!stack.isEmpty()){
            Node tmp = stack.peek();
            if (tmp.i == n - 2 && tmp.j == n - 2){
                break;
            }
                while (tmp.dir < 4){
                    switch (tmp.dir){
                        case 0:
                            x = tmp.i;
                            y = tmp.j + 1;
                            break;
                        case 1:
                            x = tmp.i + 1;
                            y = tmp.j;
                            break;
                        case 2:
                            x = tmp.i;
                            y = tmp.j - 1;
                            break;
                        case 3:
                            x = tmp.i - 1;
                            y = tmp.j;
                    }
                    tmp.dir++;
                    if (x > 0 && x < n - 1 && y > 0 && y < n - 1 && arr[x][y] != 1 && check[x][y] == 0){
                        stack.push(new Node(x, y));
                        check[x][y] = 1;
                        break;
                    }
                }
            if (tmp.dir >= 4) stack.pop();
        }
        if (stack.isEmpty()){
            System.out.print("NO");
        }else {
            Stack<Node> stack1 = new Stack<>();
            while (!stack.isEmpty()) {
                stack1.push(stack.pop());
            }
            while (!stack1.isEmpty()) {
                System.out.print(stack1.pop().toString());
            }
        }
    }
}